package com.hsck.order.kds.setup.fragment.cxzd

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.GridLayoutManager
import com.hjq.toast.Toaster
import com.hsck.order.kds.R
import com.hsck.order.kds.base.isnoam.view.BaseFragment
import com.hsck.order.kds.databinding.FragmentCxzdBinding
import com.hsck.order.kds.setup.SetupActivity
import com.hsck.order.kds.setup.adapter.CxzdAdapter

/**
 * 厨显站点
 */
class CxzdFragment : BaseFragment<FragmentCxzdBinding>(), SetupActivity.UpdatableFragment {


    private val adapter by lazy { CxzdAdapter(R.layout.item_cxzd) }

    override fun inflateBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentCxzdBinding {
        return FragmentCxzdBinding.inflate(inflater)
    }

    override fun loadDataOnce() {
        super.loadDataOnce()
        binding.apply {
            rvCxzd.layoutManager = GridLayoutManager(requireActivity(), 2)
            rvCxzd.adapter = adapter
            adapter.datas = listOf("Add", "", "", "", "", "", "")

        }

        adapter.onItemClick = {
            var cxzdDetailsFragment = CxzdDetailsFragment()//设备管理
            val activity = requireActivity() as SetupActivity
            if (it == "Add") {
                cxzdDetailsFragment.type = "Add"
            } else {
                cxzdDetailsFragment.type = "Edit"
            }
            cxzdDetailsFragment.topFragment = this
            activity.switchFragment(cxzdDetailsFragment)

        }

    }

    override fun onFragmentVisible() {
        //可见
        if (_binding != null) {

        }
    }

    override fun onFragmentInvisible() {
        //不可见

    }

}